import 'package:flutter/material.dart';
import 'package:flashapp/widgets/webview.dart';

class About extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new AboutState();
  }
}

class AboutState extends State<About> {
  bool showImage = false;
  TextStyle textStyle = new TextStyle(
    color: Colors.blue,
    decoration: new TextDecoration.combine([TextDecoration.underline])
  );

  Widget authorLink, mayunLink, githubLink;
  List<String> urls = new List();
  List<String> titles = new List();

  getLink(index) {
    String url = urls[index];
    String title = titles[index];
    print(index);
    return () {
      Navigator.of(context).push(
          new MaterialPageRoute(builder: (ctx){
            return new WebPage(
              title: title,
              url: url,
            );
          })
      );
    };
  }


  AboutState() {
    titles.add('yubos blog');
    titles.add('码云');
    titles.add('GitHub');
    urls.add("https://yubo725.top");
    urls.add("https://gitee.com/yubo725");
    urls.add("https://github.com/yubo725");

    authorLink = new GestureDetector(
      child: new Container(
        margin: const EdgeInsets.fromLTRB(0, 80, 0, 0),
        child: new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text('作者:'),
            new Text(
              'heshuai',
              style: textStyle,
            ),
          ],
        ),
      ),
      onTap: getLink(0),
    );


    mayunLink = new GestureDetector(
      child: new Container(
        margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),
        child: new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text('码云:'),
            new Text(
              'https://gitee.com/',
              style: textStyle,
            )
          ],
        )
      ),
      onTap: getLink(1),
    );

    githubLink = new GestureDetector(
      child: new Container(
        margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),
        child: new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text('Github:'),
            new Text(
              'https://github.com/',
              style: textStyle,
            )
          ],
        ),
      ),
      onTap: getLink(2),
    );
  }

  Widget getImageOrBtn() {
    if(!showImage) {
      return new Container(
        child: new Center(
          child: new InkWell(
            child: new Container(
              padding: const EdgeInsets.fromLTRB(15, 8, 15, 8),
              child: new Text('不要点我'),
              decoration: new BoxDecoration(
                border: new Border.all(color: Colors.black),
                borderRadius: new BorderRadius.all(new Radius.circular(5))
              ),
            ),
            onTap: (){
              setState(() {
                showImage = true;
              });
            },
          ),
        ),
      );
    } else {
      return new Image.asset(
        './images/ic_hongshu.jpg',
        width: 100,
        height: 100,
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('关于', style: new TextStyle(color: Colors.white)),
        iconTheme: new IconThemeData(color: Colors.white),
      ),
      body: new Center(
        child: new Column(children: <Widget>[
            new Container(
              width: 1,
              height: 100,
              color: Colors.transparent,
            ),
            new Image.asset(
              '/images/ic_osc_logo.png',
              width:200,
              height:56
            ),
            new Text('基于Google Flutter开发的客户端'),
            authorLink,
            mayunLink,
            githubLink,
            new Expanded(flex: 1,child: getImageOrBtn())
          ]
        ),
      ),
    );
  }
}